package com.myblog.common;/**
 * @Classname CommonErrorUtil
 * @Description TODO
 * @Date 2021/6/1 0001 22:54
 * @Created by Administrator
 */

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * @ClassName:CommonErrorUtil
 * @Description:返回前端的报错信息
 * @Author: qinxike
 * @Date: 2021/6/1 0001   22:54
 **/
public class CommonErrorUtil {
    public static String processErrorString(BindingResult bindingResult){
        if(!bindingResult.hasErrors()){
            return "";
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (FieldError fieldError:bindingResult.getFieldErrors()){
            stringBuilder.append(fieldError.getDefaultMessage()+",");
        }
        return stringBuilder.substring(0,stringBuilder.length()-1);
    }


}
